package com.yunhe.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.yunhe.bean.CommodityClassify;
import com.yunhe.bean.page;
import com.yunhe.test.test;

/**
 * Servlet implementation class CommodityClassifyAll_Servlet
 */
@WebServlet("/CommodityClassifyAll_Servlet")
public class CommodityClassifyAll_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CommodityClassifyAll_Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Charset", "UTF-8");

		String bigName= request.getParameter("big_name");
		//String bigName = new String(bigName1.getBytes("gbk"),"UTF-8");

		int bigId=0;
		if(request.getParameter("big_id")!=null){
			 bigId= Integer.decode(request.getParameter("big_id"));
		}
		int smallId=0;
		if(request.getParameter("small_id")!=null){
			 smallId=Integer.decode(request.getParameter("small_id"));
		}
		String smallName= request.getParameter("small_name");
		System.out.println(bigId+""+bigName+""+smallId+""+smallName+"");
		CommodityClassify cc=new CommodityClassify();
		cc.setBig_id(bigId);
		cc.setBig_name(bigName);
		cc.setSmall_id(smallId);
		cc.setSmall_name(smallName);		
		 test te =new test();
	     List<CommodityClassify> list=te.classifycla();
	     System.out.println(list);
	       Map map1=new HashMap();
	       map1.put("ClassifyList",list);
	       map1.put("CommodityClassify", cc);
	        //传递map到前端
       
			HttpSession session=request.getSession();
			session.setAttribute("map1",map1);
			//页面转向到前端
		    response.sendRedirect("manage/productClass-modify.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
